<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">

      <el-form-item label="班级名称" prop="className">
        <el-input
          v-model="queryParams.className"
          placeholder="请输入班级名称"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="班级状态"
          clearable
          size="small"
          style="width: 180px">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="班级专业" prop="classDept">
        <el-select v-model="queryParams.classSubject" clearable filterable style="width:100%">
            <el-option v-for="item in subjectList" :label="item.subjectName" placeholder="班级专业" :value="item.id" :key="item.id"></el-option>
          </el-select>

      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermi="['class:info:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermi="['class:info:batchUpdate']"
          type="warning"
          icon="el-icon-circle-check"
          size="mini"
          @click="operationStatus(1,1)"
          :disabled="multiple"
          >启用</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermi="['class:info:batchUpdate']"
          type="warning"
          icon="el-icon-circle-close"
          size="mini"
          @click="operationStatus(1,0)"
          :disabled="multiple"
          >停用</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermi="['class:info:batchUpdate']"
          type="danger"
          icon="el-icon-finished"
          size="mini"
          @click="operationStatus(2,1)"
          :disabled="multiple"
          >设置毕业</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermi="['class:info:batchUpdate']"
          type="success"
          icon="el-icon-reading"
          size="mini"
          @click="selectClassSubject"
          :disabled="multiple"
          >设置任课老师</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
                type="success"
                icon="el-icon-upload2"
                size="mini"
                @click="importData"
        >导入班级信息</el-button>
      </el-col>

    </el-row>

    <el-dialog title="导入班级信息" :visible.sync="importVisible" width="400px" >
      <el-upload v-loading="importLoading"
                 class="upload-demo"
                 drag
                 :action="upload.url"
                 :headers="upload.headers"
                 :on-success="handleAvatarSuccess"
                 :before-upload="beforeAvatarUpload"
                 :file-list="fileList"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip"><el-link type="primary" @click="importTemplateFile">模板下载</el-link></div>
      </el-upload>
    </el-dialog>

    <el-table v-loading="loading" :data="bclassList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="班级名称" align="center" prop="className" :show-overflow-tooltip="true" />
      <el-table-column label="班主任" align="center" prop="classTeacherName" :show-overflow-tooltip="true" >
        <template slot-scope="scope">
            {{ getTeacherName(scope.row.classTeacherId) }}
        </template>
      </el-table-column>
      <el-table-column label="班级人数" align="center" prop="personCount"/>
      <el-table-column label="班级年级" align="center" prop="classGrade" :show-overflow-tooltip="true" >
        <template slot-scope="scope">
            {{getDictLabel(classGradeList,scope.row.classGrade)}}
        </template>
      </el-table-column>
      <el-table-column label="班级专业" align="center" :show-overflow-tooltip="true" >
        <template slot-scope="scope">
            {{subjecLable(scope.row)}}
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="修改时间" align="center" prop="modifyTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifyTime) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="是否毕业" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.isGraduation==1?'已毕业':'未毕业' }}</span>
        </template>
      </el-table-column>

      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <el-switch
                  v-model="scope.row.status"
                  active-value="1"
                  inactive-value="0"
                  @change="handleStatusChange(scope.row)"
          />
        </template>
      </el-table-column>



      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" content="修改" v-hasPermi="['class:info:edit']" placement="top">
            <el-button size="mini" circle type="success" icon="el-icon-edit" @click="handleUpdate(scope.row)" />
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="删除" placement="top" v-hasPermi="['class:info:del']">
            <el-button size="mini" circle type="danger" icon="el-icon-delete"  @click="handleDelete(scope.row)" />
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="查看学生" placement="top">
            <el-button size="mini" circle  icon="el-icon-user"  @click="handleStudent(scope.row)" />
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="设置任课老师" placement="top">
            <el-button size="mini" circle  icon="el-icon-notebook-2"  @click="handleTeacherConfig(scope.row)" />
          </el-tooltip>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="30%" >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" >
        <el-form-item label="班级名称" prop="className">
          <el-input v-model="form.className" placeholder="请输入班级名称"   />
        </el-form-item>
        <el-form-item label="班级专业" prop="classSubject">
          <el-select v-model="form.classSubject" clearable filterable style="width:100%">
            <el-option v-for="item in subjectList" :label="item.subjectName" placeholder="班级专业" :value="item.id" :key="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="班级年级" prop="classGrade">
          <el-select v-model="form.classGrade" clearable filterable style="width:100%">
            <el-option v-for="dict in classGradeList" placeholder="班级年级"
            :key="dict.dictValue"
             :label="dict.dictLabel"
             :value="dict.dictValue" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="班主任" prop="classTeacherId">
           <el-select v-model="form.classTeacherId" filterable placeholder="请选择" style="width:100%">
             <el-option
                     v-for="item1 in userOptions"
                     :key="item1.id"
                     :label="item1.sysuName"
                     :value="item1.username"
             >
             <span style="float: left">{{ item1.sysuName }}</span>
             <span style="float: right; color: #8492a6; font-size: 13px">{{ item1.username }}</span>
            </el-option>
           </el-select>
         </el-form-item>
        <el-form-item label="助理班主任" >
           <el-select v-model="form.assistantTeacharId"  placeholder="请选择" style="width:100%">
             <el-option
                     v-for="item1 in userOptions"
                     :key="item1.id"
                     :label="item1.sysuName"
                     :value="item1.username"
             >
             <span style="float: left">{{ item1.sysuName }}</span>
             <span style="float: right; color: #8492a6; font-size: 13px">{{ item1.username }}</span>
            </el-option>
           </el-select>
         </el-form-item>
         <el-form-item label="学期" >
           <el-select v-model="form.semester"  placeholder="请选择" style="width:100%">
             <el-option
                     v-for="item1 in termTimeList"
                     :key="item1.id"
                     :label="item1.tetiBeginYear+'~'+item1.tetiEndYear"
                     :value="item1.id"
             >
             <span style="float: left">{{ item1.tetiBeginYear+'~'+item1.tetiEndYear }}</span>
            <span style="float: right; color: #8492a6; font-size: 13px">{{ item1.remarks }}</span>
            </el-option>
           </el-select>
         </el-form-item>
       <!-- <el-form-item label="所属部门" >
         <el-select
           v-model="form.classDept"
           placeholder="请选择" style="width:100%">
           <el-option
             v-for="dict in classDeptOptions"
             :key="dict.dictValue"
             :label="dict.dictLabel"
             :value="dict.dictValue"
           />
         </el-select>
       </el-form-item> -->
       <el-form-item label="状态" >
          <el-radio v-model="form.status" label="1">有效</el-radio>
          <el-radio v-model="form.status" label="0">停用</el-radio>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="班级学生信息" :visible.sync="studentDialogVisible">
      <el-table :data="studentList" style="width: 100%"  v-loading="studentLoading" >
        <el-table-column prop="studentId" label="学号"  align="center" :show-overflow-tooltip="true">
        </el-table-column>
        <el-table-column prop="name" label="姓名"  align="center" :show-overflow-tooltip="true">

        </el-table-column>
        <el-table-column prop="status" label="状态"  align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <label v-if="scope.row.status==0">无效</label>
            <label v-if="scope.row.status==1">有效</label>

          </template>
        </el-table-column>
        <el-table-column prop="phone" label="手机号" width="130"  align="center" :show-overflow-tooltip="true">
        </el-table-column>
        <el-table-column prop="gender" label="性别"  align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <label v-if="scope.row.gender==0">女</label>
            <label v-if="scope.row.gender==1">男</label>
          </template>
        </el-table-column>

        <el-table-column prop="entranceDate" label="入学年月" width="180"  align="center" :show-overflow-tooltip="true">
            <template slot-scope="scope">
            <span>{{ parseTime(scope.row.entranceDate) }}</span>
            </template>
        </el-table-column>
        <el-table-column prop="className" label="班级" align="center" :show-overflow-tooltip="true">
        </el-table-column>

      </el-table>
      <pagination
        v-show="studentTotal > 0"
        :total="studentTotal"
        :page.sync="studentParam.pageNum"
        :limit.sync="studentParam.pageSize"
        @pagination="getStudentList"
      />

    </el-dialog>

    <!-- 教员配置对话框 -->
    <el-dialog :title="configTitle" :visible.sync="configOpen" width="700px">
      <el-form  label-width="100px" inline ref="configForm" :model="configForm">
        <el-row v-for="item1,index in configForm" :key="item1.id">
          <el-col>
            <el-form-item label="教员/科目" >

              <el-select v-model="item1.userId" clearable filterable :disabled="isDisable" placeholder="请选择教员">
                <el-option v-for="item in teacherList"
                :key="item.id"
                :label="item.sysuName"
                :value="item.id" ></el-option>
              </el-select>
              <el-select v-model="item1.subjectId" clearable filterable :disabled="isDisable" placeholder="请选择科目">
                  <el-option v-for="item in classSubjectList"
                  :key="item.id"
                  :label="item.subjName"
                  :value="item.id" ></el-option>
              </el-select>

              <el-button
              size="mini"
              type="text"
              icon="el-icon-plus"
              @click="addItem"
              :disabled="isDisable"
              v-if="index==0"
            >添加科目</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-minus"
              @click="subItem(index)"
              :disabled="isDisable"
              v-if="index>0"
            >删除科目</el-button>
            </el-form-item>

          </el-col>
        </el-row>


        <!-- <el-form-item :label="'白名单IP'+(index+1)" v-for="item,index in ipList" :key="index" >
            <el-input v-model="item.ipAddress" size="mini" style="width:50%" :disabled="isDisable"></el-input>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-plus"
              @click="addIpAddress"
              :disabled="isDisable"
              v-if="index==0"
            >添加科目</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-minus"
              @click="subIpAddress(index)"
              :disabled="isDisable"
              v-if="index>0"
            >删除科目</el-button>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" :disabled="isDisable" @click="submitTeacherConfigForm">确 定</el-button>
        <el-button type="info" size="mini" icon="el-icon-edit" @click="openEdit">开启编辑</el-button>
      </div>

      <!-- <el-form ref="configForm" :model="configForm" :rules="rules" label-width="100px" >
        <el-form-item label="科目" prop="subjectId">
        <el-select v-model="configForm.subjectId" clearable filterable style="width:100%">
            <el-option v-for="item in classSubjectList" placeholder="科目"
            :key="item.id"
             :label="item.subjName"
             :value="item.id" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="教员" prop="userId">
          <el-select v-model="configForm.userId" clearable filterable style="width:100%">
            <el-option v-for="item in teacherList" placeholder="教员"
            :key="item.id"
             :label="item.sysuName"
             :value="item.id" ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTeacherConfigForm">确 定</el-button>
        <el-button @click="configCancel">取 消</el-button>
      </div> -->
    </el-dialog>
  </div>
</template>

<script>
import { findSchoolClassPageList, addOrUpdateSchoolClassInfo, deleteSchoolClassInfo, exportBClass, batchUpdateClassStatus, addTeacherRelation,classInfoImport} from "@/api/classManage/classInfo";
import { getSubjectList } from "@/api/educational/subject.js";
import { getClassTeacherList ,getAllTeacherList} from "@/api/system/user";
import { findBaseSubjectPageList} from "@/api/baseData/profession";
import { listTermtime } from "@/api/system/termtime.js";
import { originalData} from "@/api/studentInfo/infoMaintenance/index";
import { getTeacherSubjAll} from "@/api/educational/homeWork";
import { getToken } from '@/utils/auth';

export default {
  name: "BClass",
  data() {
    return {
      isDisable:true,
      // 遮罩层
      loading: true,
      // 选中数组
      rowList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      stuCount: 0,
      // 字典表格数据
      bclassList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      configForm: {},
      configTitle: "",
      configOpen: false,
      // 班主任
      userOptions: [],
      // 状态数据字典
      statusOptions: [],
      // 班级所属部门
      classDeptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        className: undefined,
        status: undefined,
        classDept:undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        className: [
          { required: true, message: "班级名称不能为空", trigger: "blur" }
        ],
        classTeacherId: [
          { required: true, message: "班主任不能为空", trigger: "blur" }
        ],
        classDept: [
          { required: true, message: "所属部门不能为空", trigger: "blur" }
        ],
        classGrade:[
          { required: true, message: "请选择班级年级", trigger: "blur" }
        ]
      },
      subjectList:[],
      termTimeList:[],
      classGradeList:[],
      studentList:[],
      studentTotal:[],
      classSubjectList: [],
      teacherList: [],
      studentParam:{
        pageSize:10,
        pageNum:1
      },
      studentLoading:false,
      studentDialogVisible:false,
      teacherSubjList:[],
      importVisible:false,
      upload:{
        url:process.env.VUE_APP_BASE_API + '/classInfo/excel/importData',
        headers: {Authorization:"Bearer " + getToken()},
      },
      fileList:[],
      importLoading:false
    };
  },
  created() {
    this.getList();
    this.getClassTeacherList();
    this.getSubjectList()
    this.getTeacherList()
    this.getTermTimeList()
    this.getClassSubjectList()
    this.getDicts("t_sys_normal_disable").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("class_dept").then(response => {
      this.classDeptOptions = response.data;
    });
    this.getDicts("class_grade").then(response => {
      this.classGradeList = response.data;
    });
  },
  methods: {
    selectClassSubject(){
      if(this.single){
        this.msgError("只能选择一个班级");
        return
      }
      this.handleTeacherConfig(this.rowList[0])
    },
    openEdit(){
      this.isDisable = false
    },
    addItem(){
        this.configForm.push({
            classId:this.classId,
            subjectId:null
        })
      },
      subItem(index){
        this.configForm.splice(index,1)
      },
    handleStudent(row){
      this.studentDialogVisible = true
      this.studentParam.classId = row.id
      this.getStudentList()
    },
    handleTeacherConfig(row){
      this.configForm = {}
      this.configTitle = "教员配置",
      this.configOpen = true
      this.classId = row.id;

      getTeacherSubjAll(row.id).then(resp=>{
        this.configForm = resp.data
        if(this.configForm.length<=0){
          this.configForm.push({
            classId:this.classId,
            subjectId:null
          })
        }
      })
    },
    getStudentList() {
      this.studentLoading = true
      originalData(this.studentParam).then((res) => {
        console.log(res);
        this.studentList = res.data.list;
        this.studentTotal = res.data.total;
        this.studentLoading = false
      });
    },
    getDictLabel(list,value){
       for(let i=0;i<list.length;i++){
        if(list[i].dictValue==value){
          return list[i].dictLabel
        }
       }
    },
    getTermTimeList() {
      //查询学期
      this.loading = true;
      listTermtime({pageSize:100,pageNum:1,status:1}).then(response => {
          this.termTimeList = response.data.list;

        }
      );
    },
    getClassSubjectList() {
       getSubjectList().then(response => {
          this.classSubjectList = response.data
       })
    },
    getSubjectList(){
      //查询专柜
      findBaseSubjectPageList({pageSize:100,pageNum:1,status:1}).then(response =>{
        this.subjectList = response.data.list
      })
    },
    /** 查询班级列表 */
    getList() {
      this.loading = true;
      findSchoolClassPageList(this.queryParams).then(response => {
          this.bclassList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    getClassTeacherList(){
      getClassTeacherList().then(response => {
        this.userOptions = response.data;
      });
    },
    getTeacherList(){
      getAllTeacherList().then(response => {
        this.teacherList = response.data;
      });
    },
    getTeacherName(val){
      for(let i=0;i<this.userOptions.length;i++){
        if(this.userOptions[i].username==val){
          return this.userOptions[i].sysuName
        }
      }
    },
    // 字典设备状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 字典设备状态字典翻译
    classDeptFormat(row, column) {
      return this.selectDictLabel(this.classDeptOptions, row.classDept);
    },
    subjecLable(row){
      for(let i=0;i<this.subjectList.length;i++){
        if(this.subjectList[i].id==row.classSubject){
          return this.subjectList[i].subjectName
        }
      }
    },
    // 班级状态修改
    handleStatusChange(row) {
        let text = row.status === "1" ? "启用" : "停用";
        this.$confirm('确认要"' + text + '""' + row.className + '"班级吗?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
            return addOrUpdateSchoolClassInfo(row);
          }).then(() => {
            this.msgSuccess(text + "成功");
          }).catch(function() {
            row.status = row.status === "0" ? "1" : "0";
          });



    },

    importTemplateFile() {
      classInfoImport().then(response => {
        console.log(response.data)
        this.fileDownload(response.data, "班级导入模板.xlsx");
      });
    },
    importData(){
      //打开导入页面
      this.importVisible = true
      this.fileList = []
    },
        //导入成功后触发
     handleAvatarSuccess(res, file){
      if(res.code==200){
        this.$message({ message: '导入成功', type: 'success'});
        this.importLoading = false
        this.importVisible = false
        this.getList()
      }else{
        this.$message.error(res.message);
        this.importLoading = false
      }
      this.fileList=[]

    },
    //导入前触发
    beforeAvatarUpload(file){
      this.importLoading = true
      console.log(file.name.lastIndexOf('.xlsx'))
      if(file.name.lastIndexOf('.xlsx')<0 && file.name.lastIndexOf('.XLSX')<0){
        this.$message({
          message: '上传文件只能是.xlsx文件',
          type: 'warning'
        });
        return false
      }
      console.log(file,'beforefile')
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        className: undefined,
        classTeacherId: undefined,
        status: "1",
        classDept:undefined,
        classSubject:undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams={
        className: undefined,
        status: undefined,
        classSubject:undefined,
        pageSize:10,
        pageNum:1
      }
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加班级信息";
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log(selection)
      this.rowList = selection

      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open = true
      this.form = row
      this.form.classSubject = row.classSubject?Number(row.classSubject):null
      this.form.semester = row.semester?Number(row.semester):null
      // this.form.classTeacherId = Number(row.classTeacherId)
      // this.form.assistantTeacharId = Number(row.assistantTeacharId)
    },
    submitTeacherConfigForm: function() {
       addTeacherRelation(this.configForm).then(response => {
        if(response.code === 200) {
          this.msgSuccess("新增成功");
          this.configOpen = false;
        } else {
           this.msgError(response.message);
        }
       })
    },
    configCancel() {
      this.configOpen = false;
      this.configForm = {};
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {

          if (this.form.id !== undefined) {
            addOrUpdateSchoolClassInfo(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.message);
              }
            });
          } else {
            addOrUpdateSchoolClassInfo(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.message);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除班级编号为"' + ids + '"的数据项?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
              }).then(function() {
                return deleteSchoolClassInfo(row);
              }).then(() => {
                this.getList();
                this.msgSuccess("删除成功");
              }).catch(function() {});




    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有班级数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportBClass(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
    // 获取当前选中班主任的名称
    selectUser(val) {
      alert(val.label);
      this.form.username = val.label
    },
    operationStatus(type,flag){
      let str=''
      if(type==1){//启用or停用

        flag==1?str='启用':str='停用'
        this.$confirm('是否确认'+str+'选中班级?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(()=> {
          for(let i=0;i<this.rowList.length;i++){
            this.rowList[i].status=flag
          }
           batchUpdateClassStatus(this.rowList).then(resp=>{
            this.msgSuccess(str+"成功");
            this.getList()
           });
        }).catch(function() {});
      }
      if(type==2){

        if(flag==1){
          str = "毕业"
        }
        this.$confirm('是否确认'+str+'选中班级?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(()=> {
          for(let i=0;i<this.rowList.length;i++){
            this.rowList[i].isGraduation=flag
          }
           batchUpdateClassStatus(this.rowList).then(resp=>{
            this.msgSuccess("成功"+str);
            this.getList()
           });
        }).catch(function() {});
      }
    }
  }
};
</script>
